var id;

$(function() {
  id = ly.getUrlParam("id");

  $(".form").getForm({
    id: id,
    type: "post",
    ajaxform: "true"
  }, function(data) {
    $("#status").getSelect({
      type: "radio",
      asName: "status",
      list: [{ "value": "0", "display": "不通过" }, { "value": "1", "display": "通过" }],
      default: data.status
    });
  });

  // 点击关闭预览图片
  $('.img-view-popup').click(function() {
    $(this).addClass('hide');
  })

});

// 预览图片
function imgView(that) {
  var imgUrl = $(that).attr('src');
  var $popupImg = $('.img-view-popup img');
  $popupImg.attr('src', imgUrl);
  $('.img-view-popup').removeClass('hide');
  $('.img-view-popup .img-view').scrollTop(0);
}

/*
 * 提交表单
 */
function submitFom() {
  var thisId = $("#currentId").val();
  var status = $("#status").find('input[name=status]:checked').val();

  var obj = {
    'id': thisId,
    'status': status
  };
  request({
    url: site.apiUrl + "/back/banner/save",
    data: obj,
    type: "post",
    ajaxform: 'true',
    callback: function(f) {
      if (f.code == 200) {
        ly.alert('编辑成功', function() {
          ly.goto("list.html");
        });
      } else {
        ly.toast(f.desc || f.message);
      }
    }
  });
}
